
/**  水印添加方法  */
let setWatermark = () => {
  let id = '1.23452384164.123412415'

  if (document.getElementById(id) !== null) {
    document.body.removeChild(document.getElementById(id))
  }

  let can = document.createElement('canvas')
  // 设置canvas画布大小
  can.width = 500
  can.height = 300

  let cans = can.getContext('2d')
  cans.rotate(-20 * Math.PI / 180) // 水印旋转角度
  const img = new Image()
  img.src = '/static/watermark.png'
  img.onload = () => {
    cans.drawImage(img, 200, 120, 127, 49)
    let div = document.createElement('div')
    div.id = id
    div.style.pointerEvents = 'none'
    div.style.top = '40px'
    div.style.left = '0px'
    div.style.opacity = '0.1'
    div.style.position = 'fixed'
    div.style.zIndex = '-1'
    div.style.width = document.documentElement.clientWidth + 'px'
    div.style.height = document.documentElement.clientHeight + 'px'
    div.style.background = 'url(' + can.toDataURL('image/png') + ') left top repeat'
    document.body.appendChild(div)
    return id
  }
}

// 添加水印方法
export const setWaterMark = () => {
  let id = setWatermark()
  if (document.getElementById(id) === null) {
    id = setWatermark()
  }
}

// 移除水印方法
export const removeWatermark = () => {
  let id = '1.23452384164.123412415'
  if (document.getElementById(id) !== null) {
    document.body.removeChild(document.getElementById(id))
  }
}
